/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
#ifndef JOYSTICK_CONTROL_SETTINGS_HANDLER_H
#define JOYSTICK_CONTROL_SETTINGS_HANDLER_H

#include <string>
#include <vector>

#include "settings.hpp"

#include "JoystickControlUtils.h"
#include "JoystickControlComponent.h"

struct AxisConfiguration {
  AxisConfiguration(const std::string aComponentName,
                    const std::string aFunctionName,
                    const int aAxisId,
                    const bool aInvert)
    : componentName (aComponentName),
      functionName (aFunctionName),
      axisId (aAxisId),
      invert (aInvert) {};
  std::string componentName;
  std::string functionName;
  int axisId;
  bool invert;
};

struct ButtonConfiguration {
  ButtonConfiguration(const std::string aComponentName,
                      const std::string aFunctionName,
                      const int aButtonId)
    : componentName (aComponentName),
      functionName (aFunctionName),
      buttonId (aButtonId) {};
  std::string componentName;
  std::string functionName;
  int buttonId;
};

typedef std::vector<AxisConfiguration> t_axisConfigVector;
typedef t_axisConfigVector::iterator t_axisConfigVectorIterator;
typedef t_axisConfigVector::const_iterator t_axisConfigVectorConstIterator;

typedef std::vector<ButtonConfiguration> t_buttonConfigVector;
typedef t_buttonConfigVector::iterator t_buttonConfigVectorIterator;
typedef t_buttonConfigVector::const_iterator t_buttonConfigVectorConstIterator;

typedef std::map< int, t_axisConfigVector > t_axisConfigMap;
typedef t_axisConfigMap::iterator t_axisConfigMapIterator;
typedef t_axisConfigMap::const_iterator t_axisConfigMapConstIterator;
typedef std::pair< int, t_axisConfigVector > t_axisConfigMapPair;

typedef std::map< int, t_buttonConfigVector > t_buttonConfigMap;
typedef t_buttonConfigMap::iterator t_buttonConfigMapIterator;
typedef t_buttonConfigMap::const_iterator t_buttonConfigMapConstIterator;
typedef std::pair< int, t_buttonConfigVector > t_buttonConfigMapPair;

class JoystickControlSettingsHandler {
  public:
    JoystickControlSettingsHandler(gim::CSettings *aSettings,
                                   const std::vector< t_stringPair > &axisList,
                                   const std::vector< t_stringPair > &buttonList);
                                   
    ~JoystickControlSettingsHandler();
    
    int listConfigurations(std::vector<std::string> &configList);
    
    int listConfigurations(wxArrayString &configList);
    
    int listAxesForConfiguration(std::vector<AxisConfiguration> &axisConfigVector,
                                 const int configId);
  
    int listButtonsForConfiguration(std::vector<ButtonConfiguration> &buttonConfigVector,
                                    const int configId);
    
  private:
    gim::CSettings *settings;
    std::string configStart;
    std::vector<std::string> confNames;
    t_axisConfigMap axisConfigList;
    t_buttonConfigMap buttonConfigList;
};

#endif // JOYSTICK_CONTROL_SETTINGS_HANDLER_H
